package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.PurchaseListGoodsService;
import com.atguigu.jxc.service.ReturnListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: ReturnListGoodsController
 * Description:
 * Date: 2022/1/17 18:14
 *
 * @version:
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/returnListGoods")
public class ReturnListGoodsController {

    @Autowired
    private ReturnListGoodsService returnListGoodsService;

    @PostMapping("/save")
    public ServiceVO saveReturnListGoods(ReturnList returnList, String returnListGoodsStr, HttpSession session){

        try {
            returnListGoodsService.saveReturnListGoods(returnList,returnListGoodsStr,session);
            return new ServiceVO<>(100,"请求成功");

        }catch (Exception e){
            e.printStackTrace();
        }

        return new ServiceVO<>(101,"添加或修改失败");
    }


    @PostMapping("/list")
    public Map<String,Object> getReturnListGoods(String returnNumber,Integer supplierId, Integer state,String sTime,String eTime){
        List<ReturnList> returnListList = returnListGoodsService.getReturnListGoods(returnNumber,supplierId,state,sTime,eTime);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",returnListList);
        return stringObjectHashMap;
    }


    @PostMapping("/goodsList")
    public Map<String,Object> getGoodsList(Integer returnListId){
        List<ReturnListGoods> returnListGoodsList = returnListGoodsService.getGoodsList(returnListId);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",returnListGoodsList);
        return stringObjectHashMap;
    }

    @PostMapping("/delete")
    public ServiceVO deleteReturnListGoods(Integer returnListId){
        try {
            returnListGoodsService.deleteReturnListGoods(returnListId);
            return new ServiceVO<>(100,"请求成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"删除失败");


    }


    @PostMapping("/count")
    public List<PurchaseListGoodsCount> count(String sTime, String eTime , Integer goodsTypeId, String codeOrName){



        List<PurchaseListGoodsCount> returnListGoodsCountList = returnListGoodsService.count(sTime, eTime ,goodsTypeId, codeOrName);


        return returnListGoodsCountList;




    }
}


